class Solution:

    def bits_of(self, n):
        if n == 0: return 0
        if n == 1: return 1
        if n > 1:
            if n % 2 == 0: return self.bits_of(n // 2)
            if n % 2 == 1: return self.bits_of(n // 2) + 1

    def countBits(self, n: int):
        bits = []
        for i in range(n + 1):
            bits.append(self.bits_of(i))
        return bits
